package com.wap;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Hashtable;

import com.base.Constant;
import com.base.DBPool;
import com.base.DatabaseDAO;
import com.base.DatabaseObject;
import com.utils.StringTool;

public class DBContentDAO extends DatabaseDAO {

	public ArrayList<DatabaseObject> getGameCategory(String parentIds,
			String ignoreIdList) {
		ArrayList<DatabaseObject> gameCategoryList = null;

		if (StringTool.isEmptyOrNul(ignoreIdList)) { 
			// Khong loai bo ID nao
			gameCategoryList = findByDynamicWhere(Constant.DB_POOL_MWAP,
					"CATEGORY", new String[] { "ID", "PARENT_ID", "CODE",
							"NAME", "DESCRIPTION", "STATUS", "CREATED",
							"MODIFIED", "ALIAS" }, new String[] { null, null,
							null, null, null, null, null, null, null },
					"status=? and PARENT_ID in (" + parentIds + ")",
					new Object[] { Integer.valueOf(1) }, "NAME");
		} else {
			gameCategoryList = findByDynamicWhere(Constant.DB_POOL_MWAP,
					"CATEGORY", new String[] { "ID", "PARENT_ID", "CODE",
							"NAME", "DESCRIPTION", "STATUS", "CREATED",
							"MODIFIED", "ALIAS" }, new String[] { null, null,
							null, null, null, null, null, null, null },
					"status=? and PARENT_ID in (" + parentIds
							+ ") and ID not in (" + ignoreIdList + ")",
					new Object[] { Integer.valueOf(1) }, "NAME");
		}
		return gameCategoryList;
	}

	public DatabaseObject getGameCategory(BigDecimal catId) {
		ArrayList<DatabaseObject> cats = findByDynamicWhere(
				Constant.DB_POOL_MWAP, "CATEGORY", new String[] { "ID",
						"PARENT_ID", "CODE", "NAME", "DESCRIPTION", "STATUS",
						"CREATED", "MODIFIED", "ALIAS" }, new String[] { null,
						null, null, null, null, null, null, null, null },
				"id=?", new Object[] { catId }, null);
		if (cats != null && !cats.isEmpty())
			return cats.get(0);
		return null;
		
	}
	public DatabaseObject getlottery_type(BigDecimal id) {
		ArrayList<DatabaseObject> cats = findByDynamicWhere(
				Constant.DB_POOL_MWAP, "lottery_type", new String[] { "LOTTERY_TYPE_ID",
						"CODE", "NAME", "CREATED", "MODIFIED", "STATUS",
						"AVATAR_IMAGE" }, new String[] { null,
						null, null, null, null, null, null},
				"lottery_type_id=?", new Object[] { id }, null);
		if (cats != null && !cats.isEmpty())
			return cats.get(0);
		return null;
		
	}
	public DatabaseObject getlottery_brand(BigDecimal id) {
		ArrayList<DatabaseObject> cats = findByDynamicWhere(
				Constant.DB_POOL_MWAP, "lottery_brand", new String[] { "LOTTERY_BRAND_ID",
						"NAME", "CREATED", "MODIFIED" },
						new String[] { null,
						null, null, null},
				"lottery_brand_id=?", new Object[] { id }, null);
		if (cats != null && !cats.isEmpty())
			return cats.get(0);
		return null;
		
	}
	public DatabaseObject getLottery_brand(BigDecimal id) {
		ArrayList<DatabaseObject> cats = findByDynamicWhere(
				Constant.DB_POOL_MWAP, "lottery_brand", new String[] { "LOTTERY_BRAND_ID","LOTTERY_SCHEDULE_ID",
						"PARENT_ID","CODE","NAME","LAST_DRAW_TIME","NEXT_DRAW_TIME","CREATED","MODIFIED","PRIORITY",
						"ALIAS","FEE"},
				new String[] { null,null,null,null,null,null,null,null,null,null,null,null,},
				"lottery_brand_id=?", new Object[] { id }, null);
		if (cats != null && !cats.isEmpty())
			return cats.get(0);
		return null;
		
	}
	public int countGameByCategory(BigDecimal catId) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		int result = 0;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			strSql = "select count(*) from vnt_media_content ctent"
					+ "	left join CONTENT_CATEGORY_MAP ccat on ctent.id=ccat.content_id"
					+ "	where ccat.category_id=? and status=1"
					+ "	order by ccat.priority";
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, catId);

			rs = preStmt.executeQuery();
			if (rs.next()) {
				result = rs.getInt(1);
			}

		} catch (Exception _e) {
			logger.error("countGameByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;

	}

	public ArrayList<DatabaseObject> getGameListByCategory(BigDecimal catId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page - 1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = "select * from ("
					+ "	select ccat.priority, ccat.category_id, ctent.id, ctent.name, ctent.SUMMARIZE, ctent.PREVIEW_IMAGE, ctent.money, rownum as r from vnt_media_content ctent"
					+ "	left join CONTENT_CATEGORY_MAP ccat on ctent.id=ccat.content_id"
					+ "	where ccat.category_id=? and status=1"
					+ "	order by ccat.priority) where r between " + startRec
					+ " and " + endRec;
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, catId);

			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("category_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("summary", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("preview_image", rs.getObject(6) == null ? ""
						: rs.getObject(6));
				attribute.put("money", rs.getObject(7) == null ? "" : rs
						.getObject(7));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;

	}

	public DatabaseObject getGameContent(BigDecimal id) {
		ArrayList<DatabaseObject> games = findByDynamicWhere(
				Constant.DB_POOL_MWAP,"vnt_media_content",
				new String[] { "id",
						"type_id", "url", "name", "summarize", "detail",
						"preview_image", "avatar_image", "avatar_image_w",
						"avatar_image_h", "status", "code", "money" },
				new String[] { null, null, null, null, null, null, null, null,
						null, null, null, null, null }, "id=?",
				new Object[] { id }, null);
		if (games != null && !games.isEmpty())
			return games.get(0);
		return null;
	}
	
	public DatabaseObject getWeatherForecasts(BigDecimal id) {
		ArrayList<DatabaseObject> games = findByDynamicWhere(
				Constant.DB_POOL_MWAP, "weather_forecasts", new String[] { "id",
						"code", "alias", "name", "content", "created","modified"},
				new String[] { null, null, null, null, null, null, null, null,
						null, null, null, null, null }, "id!=0",
				new Object[] { id }, null);
		if (games != null && !games.isEmpty())
			return games.get(0);
		return null;
	}
	// ======================================
	public ArrayList<DatabaseObject> getCategory(String parentIds,
			String ignoreIdList) {
		ArrayList<DatabaseObject> gameCategoryList = null;

		if (StringTool.isEmptyOrNul(ignoreIdList)) { // Khong loai bo ID nao
			gameCategoryList = findByDynamicWhere(Constant.DB_POOL_MWAP,
					"CATEGORY", new String[] { "ID", "PARENT_ID", "CODE",
							"NAME", "DESCRIPTION", "STATUS", "CREATED",
							"MODIFIED", "ALIAS", "AVATAR_IMAGE" }, new String[] { null, null,
							null, null, null, null, null, null, null, null },
					"status=? and ID not in ('1382') and PARENT_ID in (" + parentIds + ")",
					new Object[] { Integer.valueOf(1) }, "NAME");
		} else {
			gameCategoryList = findByDynamicWhere(Constant.DB_POOL_MWAP,
					"CATEGORY", new String[] { "ID", "PARENT_ID", "CODE",
							"NAME", "DESCRIPTION", "STATUS", "CREATED",
							"MODIFIED", "ALIAS", "AVATAR_IMAGE"}, new String[] { null, null,
							null, null, null, null, null, null, null, null },
					"status=? and PARENT_ID in (" + parentIds
							+ ") and ID not in (" + ignoreIdList + ")",
					new Object[] { Integer.valueOf(1) }, "NAME");
		}
		return gameCategoryList;
	}
	public ArrayList<DatabaseObject> getCategoryEx(String parentIds,
			String ignoreIdList) {
		ArrayList<DatabaseObject> gameCategoryList = null;

		if (StringTool.isEmptyOrNul(ignoreIdList)) { // Khong loai bo ID nao
			gameCategoryList = findByDynamicWhere(Constant.DB_POOL_MWAP,
					"CATEGORY", new String[] { "ID", "PARENT_ID", "CODE",
							"NAME", "DESCRIPTION", "STATUS", "CREATED",
							"MODIFIED", "ALIAS" }, new String[] { null, null,
							null, null, null, null, null, null, null },
					"status=? AND created >= trunc(sysdate - 1) and ID not in ('1382') and PARENT_ID in (" + parentIds + ")",
					new Object[] { Integer.valueOf(1) }, "NAME");
		} else {
			gameCategoryList = findByDynamicWhere(Constant.DB_POOL_MWAP,
					"CATEGORY", new String[] { "ID", "PARENT_ID", "CODE",
							"NAME", "DESCRIPTION", "STATUS", "CREATED",
							"MODIFIED", "ALIAS" }, new String[] { null, null,
							null, null, null, null, null, null, null },
					"status=? AND created >= trunc(sysdate - 1) and PARENT_ID in (" + parentIds
							+ ") and ID not in (" + ignoreIdList + ")",
					new Object[] { Integer.valueOf(1) }, "NAME");
		}
		return gameCategoryList;
	}
	public ArrayList<DatabaseObject> getParentGameOnline(BigDecimal parentId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			//int startRec = (page-1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;

				strSql = 
					" SELECT * FROM (SELECT id,name,description,priority,avatar_image" +
						" FROM (SELECT a.id id, a.name name, a.description description, a.priority priority, a.avatar_image avatar_image, ROWNUM AS r " +
							" FROM category a" +
							" where a.parent_id ="+parentId+" "+
							" ORDER BY a.priority ASC, a.created desc)" +
							" WHERE r <=15" +
							" ORDER BY DBMS_RANDOM.VALUE)" +
					" WHERE rownum <="+ endRec+"";
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("id", rs.getObject(1) == null ? "" : rs
						.getObject(1));
				attribute.put("name", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("description", rs.getObject(3) == null ? "" : rs
						.getObject(3));				
				attribute.put("priority", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("avatar_image", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getParentGameOnline: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public ArrayList<DatabaseObject> getCategoryOff(String parentIds,
			String ignoreIdList) {
		ArrayList<DatabaseObject> gameCategoryList = null;

		if (StringTool.isEmptyOrNul(ignoreIdList)) { // Khong loai bo ID nao
			gameCategoryList = findByDynamicWhere(Constant.DB_POOL_MWAP,
					"CATEGORY", new String[] { "ID", "PARENT_ID", "CODE",
							"NAME", "DESCRIPTION", "STATUS", "CREATED",
							"MODIFIED", "ALIAS" }, new String[] { null, null,
							null, null, null, null, null, null, null },
					"status=? and ID not in ('3627') and PARENT_ID in (" + parentIds + ")",
					new Object[] { Integer.valueOf(1) }, "NAME");
		} else {
			gameCategoryList = findByDynamicWhere(Constant.DB_POOL_MWAP,
					"CATEGORY", new String[] { "ID", "PARENT_ID", "CODE",
							"NAME", "DESCRIPTION", "STATUS", "CREATED",
							"MODIFIED", "ALIAS" }, new String[] { null, null,
							null, null, null, null, null, null, null },
					"status=? and PARENT_ID in (" + parentIds
							+ ") and ID not in ('3627') and ID not in (" + ignoreIdList + ")",
					new Object[] { Integer.valueOf(1) }, "NAME");
		}
		return gameCategoryList;
	}
	public ArrayList<DatabaseObject> getCategoryNews(String parentIds,
			String ignoreIdList) {
		ArrayList<DatabaseObject> gameCategoryList = null;

		if (StringTool.isEmptyOrNul(ignoreIdList)) { // Khong loai bo ID nao
			gameCategoryList = findByDynamicWhere(Constant.DB_POOL_MWAP,
					"CATEGORY", new String[] { "ID", "PARENT_ID", "CODE",
							"NAME", "DESCRIPTION", "STATUS", "CREATED",
							"MODIFIED", "ALIAS" }, new String[] { null, null,
							null, null, null, null, null, null, null },
					"status=? and PARENT_ID in (" + parentIds + ")"
					+ " AND created >= trunc(sysdate - 1) AND rownum between 1 and 8",
					new Object[] { Integer.valueOf(1) }, "NAME");
		} else {
			gameCategoryList = findByDynamicWhere(Constant.DB_POOL_MWAP,
					"CATEGORY", new String[] { "ID", "PARENT_ID", "CODE",
							"NAME", "DESCRIPTION", "STATUS", "CREATED",
							"MODIFIED", "ALIAS" }, new String[] { null, null,
							null, null, null, null, null, null, null },
					"status=? and PARENT_ID in (" + parentIds
							+ ") and ID not in (" + ignoreIdList + ")"
							+ " AND created >= trunc(sysdate - 1) AND rownum between 1 and 8",
					new Object[] { Integer.valueOf(1) }, "NAME");
		}
		return gameCategoryList;
	}
	public ArrayList<DatabaseObject> getContentGroup(String parentIds, 
			String ignoreIdList) {
		ArrayList<DatabaseObject> gameCategoryList = null;

		if (StringTool.isEmptyOrNul(ignoreIdList)) { // Khong loai bo ID nao
			gameCategoryList = findByDynamicWhereContentGroup(Constant.DB_POOL_MWAP,
					"CONTENT_GROUP", new String[] { "CONTENT_GROUP_ID", "PARENT_ID", "CODE",
							"ALIAS", "NAME", "CREATED", "MODIFIED"}, 
							new String[] { null, null,
							null, null, null, null, null },
					"PARENT_ID in (" + parentIds+ ") AND rownum between 1 and 10", "NAME");
		} else {
			gameCategoryList = findByDynamicWhereContentGroup(Constant.DB_POOL_MWAP,
					"CONTENT_GROUP", new String[] { "CONTENT_GROUP_ID", "PARENT_ID", "CODE",
							"ALIAS", "NAME", "CREATED", "MODIFIED"},
							new String[] { null, null,
							null, null, null, null, null },
					"PARENT_ID in (" + parentIds+ ") and CONTENT_GROUP_ID not in (" + ignoreIdList + ") AND rownum between 1 and 10", "NAME");
		}
		return gameCategoryList;
	}

	public DatabaseObject getCategory(BigDecimal catId) {
		ArrayList<DatabaseObject> cats = findByDynamicWhere(
				Constant.DB_POOL_MWAP, "CATEGORY", new String[] { "ID",
						"PARENT_ID", "CODE", "NAME", "DESCRIPTION", "STATUS",
						"CREATED", "MODIFIED", "ALIAS", "AVATAR_IMAGE" }, new String[] { null,
						null, null, null, null, null, null, null, null, null },
				"id=?", new Object[] { catId }, null);
		if (cats != null && !cats.isEmpty())
			return cats.get(0);
		return null;
	}
	public DatabaseObject getContentGroup(BigDecimal catId) {
		ArrayList<DatabaseObject> cats = findByDynamicWhere(
				Constant.DB_POOL_MWAP, "CONTENT_GROUP", new String[] { "CONTENT_GROUP_ID",
						"PARENT_ID", "CODE", "ALIAS", "NAME",
						"CREATED", "MODIFIED"}, new String[] { null,
						null, null, null, null, null, null},
				"content_group_id=?", new Object[] { catId }, null);
		if (cats != null && !cats.isEmpty())
			return cats.get(0);
		return null;
	}
	public DatabaseObject getCategoryContent(BigDecimal catId) {
		ArrayList<DatabaseObject> cats = findByDynamicWhere(
				Constant.DB_POOL_MWAP, "content_category_map", new String[] { "CONTENT_GROUP_ID",
						"PARENT_ID", "CODE", "ALIAS","NAME","CREATED","MODIFIED"},
						new String[] { null,null, null, null,
						null, null, null},
				"content_group_id=?", new Object[] { catId }, null);
		if (cats != null && !cats.isEmpty())
			return cats.get(0);
		return null;
	}
	public DatabaseObject getLotteryBrand(BigDecimal sId) {
		ArrayList<DatabaseObject> cats = findByDynamicWhere(
				Constant.DB_POOL_MWAP, "lottery_result", new String[] { "lottery_result_id",
						"lottery_brand_id", "lottery_type_id", "g_s_id","draw_time","value","created","modified"},
						new String[] { null,null, null, null,null,
						null, null, null},
				"lottery_result_id=?", new Object[] { sId }, null);
		if (cats != null && !cats.isEmpty())
			return cats.get(0);
		return null;
	}
	public int countContentByCategory(BigDecimal catId) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		int result = 0;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			strSql = "select count(*) from vnt_media_content ctent"
				+ "	left join CONTENT_CATEGORY_MAP ccat on ctent.id=ccat.content_id"
				+ "	where ccat.category_id=? and status=1"
				+ "	order by ccat.priority";
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, catId);

			rs = preStmt.executeQuery();
			if (rs.next()) {
				result = rs.getInt(1);
			}

		} catch (Exception _e) {
			logger.error("countContentByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public int countCategoryByParentID(BigDecimal parentId) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		int result = 0;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			strSql = "select count(*) from category"
				+ "	where parent_id=? and status=1";
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, parentId);

			rs = preStmt.executeQuery();
			if (rs.next()) {
				result = rs.getInt(1);
			}

		} catch (Exception _e) {
			logger.error("countCategoryByParentID: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public int countContentBy(BigDecimal sId) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		int result = 0;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			strSql = "select count(*) from weather_forecasts weat"
					+ "	order by weat.name";
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, sId);

			rs = preStmt.executeQuery();
			if (rs.next()) {
				result = rs.getInt(1);
			}

		} catch (Exception _e) {
			logger.error("countContentByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public int countContentByCategoryGroup(BigDecimal catId) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		int result = 0;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			strSql = "select count(*) from content ctent"
					+ "	left join cnt_cntg_map ccat on ctent.content_id=ccat.content_id"
					+ "	where ccat.content_group_id=?";
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, catId);

			rs = preStmt.executeQuery();
			if (rs.next()) {
				result = rs.getInt(1);
			}

		} catch (Exception _e) {
			logger.error("countContentByCategoryGroup: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public ArrayList<DatabaseObject> getContentListByCategory(BigDecimal catId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page - 1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = " SELECT * FROM ( " 
					+ " SELECT priority, category_id, ID, NAME, summarize, detail, data, preview_image,"
					+ " code, avatar_image,money, ROWNUM AS r "
					+ "	FROM (SELECT   a.priority, b.category_id, a.ID, a.NAME, a.summarize, a.detail, c.data, "
					+ "	a.preview_image, a.code, a.avatar_image, a.money"
					+ "	FROM vnt_media_content a, content_category_map b, content_instance c, content_format b"
					+ " WHERE a.ID = b.content_id(+) AND b.category_id =? AND a.ID = c.content_id AND a.status = 1"
					+ " AND c.format_id = b.ID"
					+ " ORDER BY a.priority ASC, a.created DESC))"
					+ " WHERE r between " + startRec + " and " + endRec;

			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, catId);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("category_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("summary", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("detail", rs.getObject(6) == null ? "" : rs
						.getObject(6));				
				attribute.put("data", rs.getObject(7) == null ? "" : rs
						.getObject(7));
				attribute.put("preview_image", rs.getObject(8) == null ? ""
						: rs.getObject(8));
				attribute.put("code", rs.getObject(9) == null ? "" : rs
						.getObject(9));
				attribute.put("avatar_image", rs.getObject(10) == null ? "" : rs
						.getObject(10));
				attribute.put("money", rs.getObject(11) == null ? "" : rs
						.getObject(11));				
				
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
		}
		public ArrayList<DatabaseObject> getContentListByCategoryStoryHot(BigDecimal catId,
				int page, int rowsPerPage) {
			String strSql = null;
			Connection conn = null;
			PreparedStatement preStmt = null;
			ResultSet rs = null;
			ArrayList<DatabaseObject> result = null;
			try {
				conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
				int startRec = (page - 1) * rowsPerPage + 1;
				int endRec = page * rowsPerPage;
				strSql = " SELECT * FROM ( " 
						+ " SELECT priority, category_id, ID, NAME, summarize, detail, preview_image,"
						+ " code, avatar_image, money, ROWNUM AS r "
						+ "	FROM (SELECT   a.priority, b.category_id, a.ID, a.NAME, a.summarize, a.detail,"
						+ "	a.preview_image, a.code, a.avatar_image, a.money"
						+ "	FROM vnt_media_content a, content_category_map b"
						+ " WHERE a.ID = b.content_id(+) AND b.category_id =? AND a.status = 1"
						+ " ORDER BY a.priority ASC, a.created DESC))"
						+ " WHERE r between " + startRec + " and " + endRec;

				// prepare statement
				preStmt = conn.prepareStatement(strSql);
				preStmt.setBigDecimal(1, catId);
				rs = preStmt.executeQuery();
				result = new ArrayList<DatabaseObject>();
				while (rs.next()) {
					DatabaseObject object = new DatabaseObject();
					Hashtable<String, Object> attribute = new Hashtable<String, Object>();
					attribute.put("category_id", rs.getObject(2) == null ? "" : rs
							.getObject(2));
					attribute.put("id", rs.getObject(3) == null ? "" : rs
							.getObject(3));
					attribute.put("name", rs.getObject(4) == null ? "" : rs
							.getObject(4));
					attribute.put("summary", rs.getObject(5) == null ? "" : rs
							.getObject(5));
					attribute.put("detail", rs.getObject(6) == null ? "" : rs
							.getObject(6));				
					attribute.put("preview_image", rs.getObject(7) == null ? ""
							: rs.getObject(7));
					attribute.put("code", rs.getObject(8) == null ? "" : rs
							.getObject(8));
					attribute.put("avatar_image", rs.getObject(9) == null ? "" : rs
							.getObject(9));
					attribute.put("money", rs.getObject(10) == null ? "" : rs
							.getObject(10));				
					
					object.setAttribute(attribute);
					result.add(object);
				}

			} catch (Exception _e) {
				logger.error("getGameListByCategory: Error executing " + strSql
						+ " >>> " + _e.toString());
			} finally {
				DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
			}
			return result;
		}

	public ArrayList<DatabaseObject> getContentData(BigDecimal idContent) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
	
			strSql = 
				" SELECT a.id, a.name, a.summarize, a.detail, a.preview_image," +
				" a.money, b.data, c.view_count, c.download_count" +
		        " FROM content a, content_instance b, content_view c" +
				" where a.id = b.content_id" +
				" AND a.id = c.content_id" +
				" AND a.id =?" ;

			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, idContent);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("name", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("summarize", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("detail", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("preview_image", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("money", rs.getObject(6) == null ? "" : rs
						.getObject(6));				
				attribute.put("data", rs.getObject(7) == null ? "" : rs
						.getObject(7));
				attribute.put("view_count", rs.getObject(8) == null ? ""
						: rs.getObject(8));
				attribute.put("download_count", rs.getObject(9) == null ? "" : rs
						.getObject(9));

				
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getContentData: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public ArrayList<DatabaseObject> getContentListByCategoryGameOn(BigDecimal catId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page - 1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = " SELECT * "
				+ " FROM (SELECT priority, category_id, ID, NAME, summarize, DATA, "
				+ " preview_image, code,avatar_image, money,detail, ROWNUM AS r "
				+ " FROM (SELECT   a.priority, b.category_id, a.ID, a.NAME, a.summarize, "
				+ " c.DATA, a.preview_image, a.code, d.avatar_image, a.money, a.detail "
				+ " FROM vnt_media_content a, content_category_map b,category d,content_format b, "
				+ " content_instance c "
				+ " WHERE a.ID = b.content_id(+) "
				+ " AND d.id = b.category_id "
				+ " AND b.category_id =? "
				+ " AND a.ID = c.content_id AND a.status = 1 "
				+ " AND c.format_id = b.ID"
				+ " AND b.code = 'JAR' "
				+ " ORDER BY a.priority ASC, a.created DESC)) "
				+ " WHERE r between " + startRec + " and " + endRec;

			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, catId);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("category_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("summary", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("data", rs.getObject(6) == null ? "" : rs
						.getObject(6));
				attribute.put("preview_image", rs.getObject(7) == null ? ""
						: rs.getObject(7));
				attribute.put("code", rs.getObject(8) == null ? "" : rs
						.getObject(8));
				attribute.put("avatar_image", rs.getObject(9) == null ? "" : rs
						.getObject(9));
				attribute.put("money", rs.getObject(10) == null ? "" : rs
						.getObject(10));				
				attribute.put("detail", rs.getObject(11) == null ? "" : rs
						.getObject(11));					
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public ArrayList<DatabaseObject> getContentListByCategoryFooball(BigDecimal catId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page - 1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = " SELECT * FROM ( " 
					+ " SELECT priority, category_id, ID, NAME,"
					+ " code, ROWNUM AS r "
					+ "	FROM (SELECT   a.priority, b.category_id, a.ID, c.NAME, a.code"
					+ "	FROM vnt_media_content a, content_category_map b, category c"
					+ " WHERE a.ID = b.content_id(+) AND b.category_id =? AND a.status = 1"
					+ " AND b.category_id = c.id"
					+ " ORDER BY a.priority ASC, a.created DESC))"
					+ " WHERE r between " + startRec + " and " + endRec;

			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, catId);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("category_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("code", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
		
	public ArrayList<DatabaseObject> getParentCategory(BigDecimal idparent,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page - 1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = 
				" SELECT * FROM (SELECT id, parent_id, description, priority, avatar_image, name, ROWNUM AS r " +
				" FROM ( SELECT cate.ID ID, cate.parent_id parent_id, cate.code code, cate.alias alias, cate.name name, " +
				" cate.description description, cate.priority priority, cate.avatar_image avatar_image " +
				" FROM category cate " +
				" WHERE cate.parent_id = ?" +
				" ORDER BY cate.priority ASC, cate.created DESC))" +
				" WHERE r between " + startRec+ " and "+endRec+" ";
		

			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, idparent);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("id", rs.getObject(1) == null ? "" : rs
						.getObject(1));
				attribute.put("parent_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("description", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("priority", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("avatar_image", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("name", rs.getObject(6) == null ? "" : rs
						.getObject(6));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getParentCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public ArrayList<DatabaseObject> getParentCategoryIndex1(BigDecimal idparent, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);

			strSql = 
				"SELECT * " + 
				  "FROM (SELECT   a.id, a.parent_id, a.description, a.priority, a.avatar_image, a.name " + 
				        "FROM category a " + 
				        "WHERE a.status = 1 " + 
				        "AND a.parent_id =? " + 
				        "ORDER BY DBMS_RANDOM.VALUE, a.priority ASC) " + 
				 "WHERE ROWNUM <="+rowsPerPage ;
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, idparent);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("id", rs.getObject(1) == null ? "" : rs
						.getObject(1));
				attribute.put("parent_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("description", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("priority", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("avatar_image", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("name", rs.getObject(6) == null ? "" : rs
						.getObject(6));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getParentCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public ArrayList<DatabaseObject> getContentListByCategoryDown(BigDecimal catId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page - 1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = " SELECT * FROM ( " 
					+ " SELECT priority, category_id, ID, NAME, summarize, data, preview_image,"
					+ " code, avatar_image,money, ROWNUM AS r "
					+ "	FROM (SELECT   a.priority, b.category_id, a.ID, a.NAME, a.summarize, c.data, "
					+ "	a.preview_image, a.code, a.avatar_image, a.money"
					+ "	FROM vnt_media_content a, content_category_map b, content_instance c"
					+ " WHERE a.ID = b.content_id(+) AND b.category_id =? AND a.ID = c.content_id AND a.status = 1"
					+ " ORDER BY a.priority ASC, a.created DESC))"
					+ " WHERE r between " + startRec + " and " + endRec;

			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, catId);
			//System.out.println("strSql"+strSql);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("category_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("summary", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("data", rs.getObject(6) == null ? "" : rs
						.getObject(6));
				attribute.put("preview_image", rs.getObject(7) == null ? ""
						: rs.getObject(7));
				attribute.put("code", rs.getObject(8) == null ? "" : rs
						.getObject(8));
				attribute.put("avatar_image", rs.getObject(9) == null ? "" : rs
						.getObject(9));
				attribute.put("money", rs.getObject(10) == null ? "" : rs
						.getObject(10));				
				
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;

	}
	public ArrayList<DatabaseObject> getCategoryNews1(BigDecimal catId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);//"ID", "PARENT_ID", "CODE",
		//	"NAME", "DESCRIPTION", "STATUS", "CREATED",
		//	"MODIFIED", "ALIAS" 
			int startRec = (page - 1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = " select id,parent_id,code,name,description,alias " 
					+ " from CATEGORY a where parent_id = ? and status=1"
					+ " and a.created >= trunc(sysdate - 1)" 
					+" and r between " + startRec + " and " + endRec;

			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, catId);
			//System.out.println("strSql"+strSql);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("id", rs.getObject(1) == null ? "" : rs
						.getObject(1));
				attribute.put("parent_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("code", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("description", rs.getObject(5) == null ? ""
						: rs.getObject(5));
				attribute.put("alias", rs.getObject(6) == null ? "" : rs
						.getObject(6));
				attribute.put("avatar_image", rs.getObject(8) == null ? "" : rs
						.getObject(8));
				attribute.put("money", rs.getObject(9) == null ? "" : rs
						.getObject(9));				
				
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getCategoryNews1: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;

	}
	public ArrayList<DatabaseObject> getContentListByCategoryNews(BigDecimal catId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page - 1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = " SELECT * FROM ( " 
					+ " SELECT priority, category_id, ID, NAME, summarize, preview_image,"
					+ " code, avatar_image,money, ROWNUM AS r "
					+ "	FROM (SELECT   a.priority, b.category_id, a.ID, a.NAME, a.summarize,"
					+ "	a.preview_image, a.code, a.avatar_image, a.money"
					+ "	FROM vnt_media_content a, content_category_map b"
					+ " WHERE a.ID = b.content_id(+) AND b.category_id =? AND a.status = 1"
					+ " ORDER BY a.priority ASC, a.created DESC))"
					+ " WHERE r between " + startRec + " and " + endRec;

			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, catId);
			//System.out.println("strSql"+strSql);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("category_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("summary", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("preview_image", rs.getObject(6) == null ? ""
						: rs.getObject(6));
				attribute.put("code", rs.getObject(7) == null ? "" : rs
						.getObject(7));
				attribute.put("avatar_image", rs.getObject(8) == null ? "" : rs
						.getObject(8));
				attribute.put("money", rs.getObject(9) == null ? "" : rs
						.getObject(9));				
				
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;

	}
	public ArrayList<DatabaseObject> getContentListByCategoryGroup(BigDecimal catId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page - 1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = "select * from ("
					+ "	select ccat.content_group_id, ctent.content_id, ctent.name,ctent.data, ctent.code, rownum as r "
					+ " from content ctent, cnt_cntg_map ccat"
					+ "	where ctent.content_id=ccat.content_id and ccat.content_group_id=?"
					+ " order by ctent.created desc"
					+ ") where r between " + startRec
					+ " and " + endRec;
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, catId);

			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("content_group_id", rs.getObject(1) == null ? "" : rs
						.getObject(1));
				attribute.put("content_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("name", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("data", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("code", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;

	}
	public ArrayList<DatabaseObject> getListWeather() {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			//int startRec = (page - 1) * rowsPerPage + 1;
			//int endRec = page * rowsPerPage;
			strSql = "SELECT   a.id, a.code, a.alias, a.name, a.content,"
					+ "TO_CHAR (a.created, 'dd/MM/yyyy hh24:mi:ss') created,"
					+ "TO_CHAR (a.modified, 'dd/MM/yyyy hh24:mi:ss') modified "
					+ "FROM weather_forecasts a ORDER BY a.code ASC ";
	                //+ " where rownum between " + startRec+ " and "+endRec+" ";
			//prepare statement
			preStmt = conn.prepareStatement(strSql);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("id", rs.getObject(1) == null ? "" : rs
						.getObject(1));
				attribute.put("code", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("alias", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("content", rs.getObject(5) == null ? ""
						: rs.getObject(5));
				attribute.put("created", rs.getObject(6) == null ? "" : rs
						.getObject(6));
				attribute.put("modified", rs.getObject(7) == null ? "" : rs
						.getObject(7));

				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getListWeather: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}

	public ArrayList<DatabaseObject> getListLotteryBrand(BigDecimal sId) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			strSql = "SELECT   a.lottery_result_id lottery_result_id, b.NAME name, a.lottery_type_id lottery_type_id, a.value value," +
					"TO_CHAR (a.draw_time, 'dd/MM/yyyy hh24:mi:ss') draw_time," +
					"TO_CHAR (a.modified, 'dd/MM/yyyy') modified " +
					"FROM lottery_result a, lottery_brand b " +
					"WHERE a.lottery_brand_id = b.lottery_brand_id " +
					"AND a.draw_time >= TRUNC (SYSDATE-1) AND a.lottery_type_id =?" +
					"ORDER BY a.draw_time DESC";
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, sId);

			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("lottery_result_id", rs.getObject(1) == null ? "" : rs
						.getObject(1));
				attribute.put("name", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("lottery_type_id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("value", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("draw_time", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("modified", rs.getObject(6) == null ? "" : rs
						.getObject(6));
				object.setAttribute(attribute);
				result.add(object);
			}
		} catch (Exception _e) {
			logger.error("getLottery Result: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;

	}
	public ArrayList<DatabaseObject> getListLotteryBrand3(BigDecimal pId, BigDecimal sId ) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			strSql = "SELECT   a.lottery_result_id lottery_result_id, b.NAME name, a.lottery_type_id lottery_type_id, a.value value," +
					"TO_CHAR (a.created, 'dd/MM/yyyy') created," +
					"TO_CHAR (a.modified, 'dd/MM/yyyy') modified " +
					"FROM lottery_result a, lottery_brand b " +
					"WHERE a.lottery_brand_id = b.lottery_brand_id " +
					"AND a.created >= TRUNC (SYSDATE) AND a.lottery_type_id =" + pId +
					"AND a.lottery_result_id =" + sId +
					"ORDER BY a.created DESC";
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, sId);

			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("lottery_result_id", rs.getObject(1) == null ? "" : rs
						.getObject(1));
				attribute.put("name", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("lottery_type_id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("value", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("created", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("modified", rs.getObject(6) == null ? "" : rs
						.getObject(6));
				object.setAttribute(attribute);
				result.add(object);
			}
		} catch (Exception _e) {
			logger.error("getLottery Result: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;

	}
	public ArrayList<DatabaseObject> getListLotteryBrandTwo(BigDecimal sId, BigDecimal pId) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			strSql = "SELECT   a.lottery_result_id lottery_result_id, b.NAME name, a.lottery_type_id lottery_type_id, a.value value," +
					"TO_CHAR (a.created, 'dd/MM/yyyy') created," +
					"TO_CHAR (a.modified, 'dd/MM/yyyy') modified " +
					"FROM lottery_result a, lottery_brand b " +
					"WHERE a.lottery_brand_id = b.lottery_brand_id " +
					"AND a.created >= TRUNC (SYSDATE - 1) AND a.lottery_type_id ="+sId+
					"AND a.lottery_result_id ="+pId+
					"ORDER BY a.created DESC";
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, sId);

			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("lottery_result_id", rs.getObject(1) == null ? "" : rs
						.getObject(1));
				attribute.put("name", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("lottery_type_id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("value", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("created", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("modified", rs.getObject(6) == null ? "" : rs
						.getObject(6));
				object.setAttribute(attribute);
				result.add(object);
			}
		} catch (Exception _e) {
			logger.error("getLottery Result: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;

	}
	public ArrayList<DatabaseObject> getListLotteryBrandDetail(BigDecimal sType) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			strSql = " SELECT a.lottery_type_id lottery_type_id, c.lottery_result_id lottery_result_id, b.NAME NAME, c.VALUE VALUE, " +
					" TO_CHAR (c.created, 'dd/MM/yyyy') created" +
					" FROM lottery_type a, lottery_brand b, lottery_result c " +
					" WHERE a.lottery_type_id = b.lottery_brand_id" +
					" AND b.lottery_brand_id = c.lottery_brand_id" +
					" AND c.lottery_type_id =? "+
					" AND c.lottery_result_id = 12215" +
					" ORDER BY c.created DESC";
				// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, sType);

			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("lottery_type_id", rs.getObject(1) == null ? "" : rs
						.getObject(1));
				attribute.put("lottery_result_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("name", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("value", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("created", rs.getObject(5) == null ? "" : rs
						.getObject(5));

				object.setAttribute(attribute);
				result.add(object);
			}
		} catch (Exception _e) {
			logger.error("getLottery Result: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;

	}
	public ArrayList<DatabaseObject> getListLotteryType() {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			strSql = "SELECT   a.lottery_type_id, a.code, a.name,"
					+ "TO_CHAR (a.created, 'dd/MM/yyyy hh24:mi:ss') created,"
					+ "TO_CHAR (a.modified, 'dd/MM/yyyy hh24:mi:ss') modified,"
					+ "status FROM lottery_type a " 
					+ "WHERE a.lottery_type_id NOT IN ('45')" 
					+ "ORDER BY a.name ASC ";
			//prepare statement
			preStmt = conn.prepareStatement(strSql);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("lottery_type_id", rs.getObject(1) == null ? "" : rs
						.getObject(1));
				attribute.put("code", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("name", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("created", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("modified", rs.getObject(5) == null ? ""
						: rs.getObject(5));
				attribute.put("status", rs.getObject(6) == null ? "" : rs
						.getObject(6));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getListType: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public ArrayList<DatabaseObject> getContentGameOnlineListByType(BigDecimal typeId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page - 1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = " SELECT * "
				+ " FROM (SELECT priority, category_id, ID, NAME, summarize, DATA, "
				+ " preview_image, code,avatar_image, money,detail, ROWNUM AS r "
				+ " FROM (SELECT   a.priority, b.category_id, a.ID, a.NAME, a.summarize, "
				+ " c.DATA, a.preview_image, a.code, d.avatar_image, a.money, a.detail "
				+ " FROM vnt_media_content a, content_category_map b,category d,content_format b, "
				+ " content_instance c "
				+ " WHERE a.ID = b.content_id(+) "
				+ " AND a.type_id = ?"
				+ " AND d.id = b.category_id "
				+ " AND b.category_id = 3627 "
				+ " AND a.ID = c.content_id "
				+ " AND a.status = 1 "
				+ " AND c.format_id = b.ID"
				+ " AND b.code = 'JAR' "
				+ " ORDER BY a.priority ASC, a.created DESC)) "
				+ " WHERE r between " + startRec + " and " + endRec;

			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, typeId);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("category_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("summary", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("data", rs.getObject(6) == null ? "" : rs
						.getObject(6));
				attribute.put("preview_image", rs.getObject(7) == null ? ""
						: rs.getObject(7));
				attribute.put("code", rs.getObject(8) == null ? "" : rs
						.getObject(8));
				attribute.put("avatar_image", rs.getObject(9) == null ? "" : rs
						.getObject(9));
				attribute.put("money", rs.getObject(10) == null ? "" : rs
						.getObject(10));				
				attribute.put("detail", rs.getObject(11) == null ? "" : rs
						.getObject(11));					
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public ArrayList<DatabaseObject> getContentGameOffListByType(BigDecimal typeId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page - 1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = " SELECT   priority, category_id, ID, NAME, summarize, data, preview_image, code, detail, avatar_image, money " +
	         		 " FROM (SELECT   ctent.priority priority, ccat.category_id category_id, " +
	                                " ctent.ID ID, ctent.NAME NAME, ctent.summarize summarize, a.data data, " +
	                                " ctent.preview_image preview_image, ctent.code code, ctent.detail detail, " +
	                                " ctent.avatar_image avatar_image, ctent.money money " +
	                        " FROM vnt_media_content ctent, content_category_map ccat , content_instance a, content_format b" +
	                        " WHERE ctent.ID = ccat.content_id(+) AND ctent.ID = a.content_id(+) AND a.format_id = b.ID(+)" +	
	                        " AND ctent.type_id = ? AND ccat.category_id = 172" + //game hanh dong mao hiem
	                        " AND ctent.status = 1 AND b.code = 'JAR' " +
	                        " AND ctent.avatar_image IS NOT NULL " +
	                        " AND ctent.preview_image IS NOT NULL " +
	                        " ORDER BY ctent.priority ASC,DBMS_RANDOM.VALUE)" +
	                        " WHERE rownum between " + startRec+ " and "+endRec+" ";

			//prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, typeId);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("category_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("summary", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("data", rs.getObject(6) == null ? "" : rs
						.getObject(6));				
				attribute.put("preview_image", rs.getObject(7) == null ? ""
						: rs.getObject(7));
				attribute.put("code", rs.getObject(8) == null ? "" : rs
						.getObject(8));
				attribute.put("detail", rs.getObject(9) == null ? "" : rs
						.getObject(9));				
				attribute.put("avatar_image", rs.getObject(10) == null ? "" : rs
						.getObject(10));
				attribute.put("money", rs.getObject(11) == null ? "" : rs
						.getObject(11));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;

	}
	public ArrayList<DatabaseObject> getContentListByType(BigDecimal typeId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page - 1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = " SELECT   priority, category_id, ID, NAME, summarize, data, preview_image, code, avatar_image, money " +
	         		 " FROM (SELECT   ctent.priority priority, ccat.category_id category_id, " +
	                                " ctent.ID ID, ctent.NAME NAME, ctent.summarize summarize, a.data data, " +
	                                " ctent.preview_image preview_image, ctent.code code, " +
	                                " ctent.avatar_image avatar_image, ctent.money money " +
	                        " FROM vnt_media_content ctent, content_category_map ccat , content_instance a, content_format b" +
	                        " WHERE ctent.ID = ccat.content_id(+) AND ctent.ID = a.content_id(+) AND a.format_id = b.ID(+)" +
	                        " AND ctent.type_id = ? " +
	                        " AND ctent.status = 1" +
	                        " AND ctent.avatar_image IS NOT NULL " +
	                        " AND ctent.preview_image IS NOT NULL " +
	                        " ORDER BY ctent.priority ASC, DBMS_RANDOM.VALUE)" +
	                        " WHERE rownum between " + startRec+ " and "+endRec+" ";
			//prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, typeId);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("category_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("summary", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("data", rs.getObject(6) == null ? "" : rs
						.getObject(6));				
				attribute.put("preview_image", rs.getObject(7) == null ? ""
						: rs.getObject(7));
				attribute.put("code", rs.getObject(8) == null ? "" : rs
						.getObject(8));
				attribute.put("avatar_image", rs.getObject(9) == null ? "" : rs
						.getObject(9));
				attribute.put("money", rs.getObject(10) == null ? "" : rs
						.getObject(10));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;

	}
	public ArrayList<DatabaseObject> getContentListByTypeIndexAll(BigDecimal typeId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page - 1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = " SELECT * FROM (SELECT   priority, category_id, ID, NAME, summarize, data, preview_image, code, avatar_image, money " +
	         		 " FROM (SELECT   ctent.priority priority, ccat.category_id category_id, " +
	                                " ctent.ID ID, ctent.NAME NAME, ctent.summarize summarize, a.data data, " +
	                                " ctent.preview_image preview_image, ctent.code code, " +
	                                " ctent.avatar_image avatar_image, ctent.money money " +
	                        " FROM vnt_media_content ctent, content_category_map ccat , content_instance a, category cate, content_format b" +
	                        " WHERE ctent.ID = ccat.content_id(+) AND ctent.ID = a.content_id(+) AND a.format_id = b.ID(+)" +
	                        " AND cate.id = ccat.category_id " +
	                        " AND ccat.category_id = 325 " +
	                        " AND ctent.type_id = ? " +
	                        " AND ctent.status = 1" +
	                        " AND ctent.avatar_image IS NOT NULL " +
	                        " AND ctent.preview_image IS NOT NULL " +
	                        " ORDER BY ctent.priority ASC, ctent.created DESC)" +
	                        " WHERE ROWNUM < 15 " +
	                        " ORDER BY DBMS_RANDOM.VALUE) " +
	                        " WHERE rownum <="+endRec+ " ";
			//prepare statement
			preStmt = conn.prepareStatement(strSql);
			//System.out.println("strSql"+strSql);
			preStmt.setBigDecimal(1, typeId);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("category_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("summary", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("data", rs.getObject(6) == null ? "" : rs
						.getObject(6));				
				attribute.put("preview_image", rs.getObject(7) == null ? ""
						: rs.getObject(7));
				attribute.put("code", rs.getObject(8) == null ? "" : rs
						.getObject(8));
				attribute.put("avatar_image", rs.getObject(9) == null ? "" : rs
						.getObject(9));
				attribute.put("money", rs.getObject(10) == null ? "" : rs
						.getObject(10));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;

	}
	public ArrayList<DatabaseObject> getContentListByTypeGameOff(BigDecimal typeId,
      int page, int rowsPerPage) {
    String strSql = null;
    Connection conn = null;
    PreparedStatement preStmt = null;
    ResultSet rs = null;
    ArrayList<DatabaseObject> result = null;
    try {
      conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
      int startRec = (page - 1) * rowsPerPage + 1;
      int endRec = page * rowsPerPage;
      strSql = " SELECT * FROM (SELECT   priority, category_id, ID, NAME, summarize, data, preview_image, code, avatar_image, money " +
               " FROM (SELECT   ctent.priority priority, ccat.category_id category_id, " +
                                  " ctent.ID ID, ctent.NAME NAME, ctent.summarize summarize, a.data data, " +
                                  " ctent.preview_image preview_image, ctent.code code, " +
                                  " ctent.avatar_image avatar_image, ctent.money money " +
                          " FROM vnt_media_content ctent, content_category_map ccat , content_instance a, category cate, content_format b" +
                          " WHERE ctent.ID = ccat.content_id(+) AND ctent.ID = a.content_id(+) AND a.format_id = b.ID(+)" +
                          " AND cate.id = ccat.category_id " +
                          " AND ctent.type_id = ? " +
                          " AND ccat.category_id not in ('3627')" +
                          " AND ctent.status = 1" +
                          " AND ctent.avatar_image IS NOT NULL " +
                          " AND ctent.preview_image IS NOT NULL " +
                          " ORDER BY ctent.priority ASC, ctent.created DESC)" +
                          " WHERE ROWNUM < 10 " +
                          " ORDER BY DBMS_RANDOM.VALUE) " +
                          " WHERE rownum <="+endRec+ " ";
      //prepare statement
      preStmt = conn.prepareStatement(strSql);
      //System.out.println("strSql"+strSql);
      preStmt.setBigDecimal(1, typeId);
      rs = preStmt.executeQuery();
      result = new ArrayList<DatabaseObject>();
      while (rs.next()) {
        DatabaseObject object = new DatabaseObject();
        Hashtable<String, Object> attribute = new Hashtable<String, Object>();
        attribute.put("category_id", rs.getObject(2) == null ? "" : rs
            .getObject(2));
        attribute.put("id", rs.getObject(3) == null ? "" : rs
            .getObject(3));
        attribute.put("name", rs.getObject(4) == null ? "" : rs
            .getObject(4));
        attribute.put("summary", rs.getObject(5) == null ? "" : rs
            .getObject(5));
        attribute.put("data", rs.getObject(6) == null ? "" : rs
            .getObject(6));       
        attribute.put("preview_image", rs.getObject(7) == null ? ""
            : rs.getObject(7));
        attribute.put("code", rs.getObject(8) == null ? "" : rs
            .getObject(8));
        attribute.put("avatar_image", rs.getObject(9) == null ? "" : rs
            .getObject(9));
        attribute.put("money", rs.getObject(10) == null ? "" : rs
            .getObject(10));
        object.setAttribute(attribute);
        result.add(object);
      }

    } catch (Exception _e) {
      logger.error("getGameListByCategory: Error executing " + strSql
          + " >>> " + _e.toString());
    } finally {
      DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
    }
    return result;

  } 
	//getContentToneListByType
	public ArrayList<DatabaseObject> getContentListByTypeNews(BigDecimal typeId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page - 1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = " SELECT   priority, category_id, ID, NAME, summarize, preview_image, code, avatar_image, money " +
	         		 " FROM (SELECT   ctent.priority priority, ccat.category_id category_id, " +
	                                " ctent.ID ID, ctent.NAME NAME, ctent.summarize summarize, " +
	                                " ctent.preview_image preview_image, ctent.code code, " +
	                                " ctent.avatar_image avatar_image, ctent.money money " +
	                        " FROM vnt_media_content ctent, content_category_map ccat, category cate, content_instance a, content_format b" +
	                        " WHERE ctent.ID = ccat.content_id(+) AND ctent.ID = a.content_id(+) AND ccat.category_id = cate.id (+) AND a.format_id = b.ID(+)" +
	                        " AND ctent.type_id = ? " +
	                        " AND ctent.status = 1" +
	                        " AND ctent.created >= trunc(sysdate -1) AND cate.parent_id not in('3217') " + //loai haivl
	                        " AND cate.parent_id NOT IN('3248')" +
	                        " AND ctent.preview_image IS NOT NULL " +
	                        " ORDER BY ctent.priority ASC, ctent.created DESC)" +
	                        " WHERE rownum between " + startRec+ " and "+endRec+" ";
			//prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, typeId);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("category_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("summary", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("preview_image", rs.getObject(6) == null ? ""
						: rs.getObject(6));
				attribute.put("code", rs.getObject(7) == null ? "" : rs
						.getObject(7));
				attribute.put("avatar_image", rs.getObject(8) == null ? "" : rs
						.getObject(8));
				attribute.put("money", rs.getObject(9) == null ? "" : rs
						.getObject(9));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;

	}
	public ArrayList<DatabaseObject> getContentToneListByType(BigDecimal typeId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page - 1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = " SELECT   priority, category_id, ID, NAME, summarize, data, preview_image, code, avatar_image, money " +
	         		 " FROM (SELECT   ctent.priority priority, ccat.category_id category_id, " +
	                                " ctent.ID ID, ctent.NAME NAME, ctent.summarize summarize, a.data data, " +
	                                " ctent.preview_image preview_image, ctent.code code, " +
	                                " ctent.avatar_image avatar_image, ctent.money money " +
	                        " FROM vnt_media_content ctent, content_category_map ccat , content_instance a, content_format b" +
	                        " WHERE ctent.ID = ccat.content_id(+) AND ctent.ID = a.content_id(+) AND a.format_id = b.ID(+)" +	
	                        " AND ctent.type_id = ? " +
	                        " AND ctent.status = 1 AND (b.code = 'MP3' OR b.code = 'MP4') " +
	                        " AND ctent.avatar_image IS NOT NULL " +
	                        " AND ctent.preview_image IS NOT NULL " +
	                        " ORDER BY ctent.priority ASC, DBMS_RANDOM.VALUE)" +
	                        " WHERE rownum between " + startRec+ " and "+endRec+" ";

			//prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, typeId);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("category_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("summary", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("data", rs.getObject(6) == null ? "" : rs
						.getObject(6));				
				attribute.put("preview_image", rs.getObject(7) == null ? ""
						: rs.getObject(7));
				attribute.put("code", rs.getObject(8) == null ? "" : rs
						.getObject(8));
				attribute.put("avatar_image", rs.getObject(9) == null ? "" : rs
						.getObject(9));
				attribute.put("money", rs.getObject(10) == null ? "" : rs
						.getObject(10));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public ArrayList<DatabaseObject> getContentListByTypeVn(BigDecimal typeId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page - 1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = " SELECT   content_group_id,content_id, NAME, code " +
	         		 " FROM (SELECT   ccat.content_group_id content_group_id, " +
	                                " ctent.content_id content_id, ctent.NAME NAME, " +
	                                " ctent.code code " +
	                        " FROM content ctent, cnt_cntg_map ccat " +
	                        " WHERE ctent.content_id = ccat.content_id(+) " +	
	                        " AND ctent.content_type_id = ? " +
	                        " ORDER BY ctent.created DESC)" +
	                        " WHERE rownum between " + startRec+ " and "+endRec;
			//prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, typeId);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("content_group_id", rs.getObject(1) == null ? "" : rs
						.getObject(1));
				attribute.put("content_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("name", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategoryVn: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;

	}
	public ArrayList<DatabaseObject> getContentHOTListByType(BigDecimal typeId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			// int startRec = (page-1) * rowsPerPage + 1;
			// int endRec = page * rowsPerPage;
			strSql = "SELECT * FROM ("
					+ " SELECT ccat.priority, ccat.category_id, ctent.id, ctent.name, ctent.SUMMARIZE, ctent.PREVIEW_IMAGE,"
					+ " ctent.code, ctent.AVATAR_IMAGE, ctent.money money, a.data data "
					+ " from vnt_media_content ctent, content_instance a, CONTENT_CATEGORY_MAP ccat, content_view ctview"
					+ " WHERE ctent.id=ccat.content_id "
					+ " AND ctent.id = a.content_id "
					+ " AND ctent.id = ctview.content_id "
					+ " AND ctent.status=1 and ctent.type_id=?"
					+ " AND ctent.preview_image IS NOT NULL"
					+ " AND ctent.avatar_image IS NOT NULL"
					+ " AND instr(ctent.preview_image,'PROMOTION_GIRL') <=0"
					+ " AND instr(ctent.preview_image,'_PG') <=0"
					+ " ORDER BY ctview.view_count desc,ctview.download_count desc)WHERE rownum <= 6";

			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, typeId);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("category_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("summary", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("preview_image", rs.getObject(6) == null ? ""
						: rs.getObject(6));
				attribute.put("code", rs.getObject(7) == null ? "" : rs
						.getObject(7));
				attribute.put("avatar_image", rs.getObject(8) == null ? "" : rs
						.getObject(8));
				attribute.put("money", rs.getObject(9) == null ? "" : rs
						.getObject(9)); 
				attribute.put("data", rs.getObject(10) == null ? "" : rs
						.getObject(10)); 				
				
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public ArrayList<DatabaseObject> getContentHOTClipListByType(BigDecimal typeId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			// int startRec = (page-1) * rowsPerPage + 1;
			// int endRec = page * rowsPerPage;
			strSql = "SELECT * FROM ("
					+ " SELECT ccat.priority, ccat.category_id, ctent.id, ctent.name, ctent.SUMMARIZE, ctent.PREVIEW_IMAGE,"
					+ " ctent.code, ctent.AVATAR_IMAGE, ctent.money money, a.data data "
					+ " from vnt_media_content ctent, content_instance a, CONTENT_CATEGORY_MAP ccat, category cate, content_view ctview"
					+ " WHERE ctent.id=ccat.content_id "
					+ " AND cate.id = ccat.category_id " 
					+ " AND ccat.category_id = 325 " 
					+ " AND ctent.id = a.content_id "
					+ " AND ctent.id = ctview.content_id "
					+ " AND ctent.status=1 and ctent.type_id=?"
					+ " AND ctent.preview_image IS NOT NULL"
					+ " AND ctent.avatar_image IS NOT NULL"
					+ " AND instr(ctent.preview_image,'PROMOTION_GIRL') <=0"
					+ " AND instr(ctent.preview_image,'_PG') <=0"
					+ " ORDER BY ctview.view_count desc,ctview.download_count desc)WHERE rownum <= 6";

			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, typeId);
			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("category_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("summary", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("preview_image", rs.getObject(6) == null ? ""
						: rs.getObject(6));
				attribute.put("code", rs.getObject(7) == null ? "" : rs
						.getObject(7));
				attribute.put("avatar_image", rs.getObject(8) == null ? "" : rs
						.getObject(8));
				attribute.put("money", rs.getObject(9) == null ? "" : rs
						.getObject(9)); 
				attribute.put("data", rs.getObject(10) == null ? "" : rs
						.getObject(10)); 				
				
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}	
	public ArrayList<DatabaseObject> getCategoryListByParent(BigDecimal parentId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page-1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
			strSql = " SELECT * FROM (SELECT parent_id, ID, code, alias, name, description, priority, avatar_image,ROWNUM AS r " +
			" FROM ( SELECT cate.parent_id parent_id, cate.ID ID, cate.code code, cate.alias alias, cate.name name, " +
			" cate.description description, cate.priority priority, cate.avatar_image avatar_image " +
			" FROM category cate " +
			" WHERE cate.parent_id = ?" +
			" ORDER BY cate.priority ASC, cate.created DESC))" +
			" WHERE r between " + startRec+ " and "+endRec+" ";
	

	// prepare statement
	preStmt = conn.prepareStatement(strSql);
	preStmt.setBigDecimal(1, parentId);

	rs = preStmt.executeQuery();
	result = new ArrayList<DatabaseObject>();
	while (rs.next()) {
		DatabaseObject object = new DatabaseObject();
		Hashtable<String, Object> attribute = new Hashtable<String, Object>();
		attribute.put("id", rs.getObject(2) == null ? "" : rs
				.getObject(2));
		attribute.put("code", rs.getObject(3) == null ? "" : rs
				.getObject(3));
		attribute.put("alias", rs.getObject(4) == null ? "" : rs
				.getObject(4));
		attribute.put("name", rs.getObject(5) == null ? "" : rs
				.getObject(5));
		attribute.put("description", rs.getObject(6) == null ? ""
				: rs.getObject(6));
		attribute.put("priority", rs.getObject(7) == null ? ""
				: rs.getObject(7));
		attribute.put("avatar_image", rs.getObject(8) == null ? "" : rs
				.getObject(8));
		object.setAttribute(attribute);
		result.add(object);
	}

} catch (Exception _e) {
	logger.error("getGamListbyParent: Error executing " + strSql
			+ " >>> " + _e.toString());
} finally {
	DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
}
return result;
}

	public ArrayList<DatabaseObject> getCategoryListByParentHOT(BigDecimal parentId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page-1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
				strSql =  " SELECT * FROM ( " +
						" SELECT id, NAME, priority, sl, description, avatar_image, ROWNUM AS r " +
						" FROM (SELECT k.id id, k.NAME NAME, k.priority priority, k.sl sl, " +
								"v.description description, v.avatar_image avatar_image" +
										" FROM (SELECT  d.id id, d.description description,d.avatar_image avatar_image" +
						  						 " FROM vnt_media_content a,content_category_map b,content_view c,CATEGORY d " +
						  					 " WHERE a.id = b.content_id(+)" +
						  					 " AND b.category_id = d.id(+)" +
						  					 " AND a.id = c.content_id(+)" +
						  					 " AND b.category_id IN (SELECT ID" +
						  											 " FROM CATEGORY" +
						  											 " WHERE parent_id ="+parentId+")" +
						  				 " GROUP BY d.id, d.description, d.avatar_image) v," +
						  				 " (SELECT   d.ID, d.NAME NAME, d.priority priority, SUM (c.download_count) sl" +
						  					 " FROM vnt_media_content a, content_category_map b, content_view c, CATEGORY d" +
						  					 " WHERE a.id = b.content_id(+)" +
						  					 " AND b.category_id = d.id(+)" +
						  					 " AND a.id = c.content_id(+)" +
						  					 " AND b.category_id IN (SELECT ID" +
						  											 " FROM CATEGORY" +
						  											 " WHERE parent_id ="+parentId+")" +
						  				 " GROUP BY d.ID, d.NAME, d.priority" +
						  				 " ORDER BY priority ASC) k" +
						  	 " WHERE v.ID = k.ID))" +
						" WHERE r between " + startRec+ " and "+endRec+" ";

			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			rs = preStmt.executeQuery();
			//System.out.println(strSql);
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("id", rs.getObject(1) == null ? "" : rs
						.getObject(1));
				attribute.put("name", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("priority", rs.getObject(3) == null ? "" : rs
						.getObject(3));				
				attribute.put("sl", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("description", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("avatar_image", rs.getObject(6) == null ? "" : rs
						.getObject(6));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListbyParent: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public ArrayList<DatabaseObject> getParentCategoryIndex(BigDecimal parentId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			//int startRec = (page-1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;

				strSql = " SELECT * " +
					" FROM (SELECT ID, NAME, priority,sl, description, avatar_image, ROWNUM AS r " +
							" FROM (SELECT   k.ID ID, k.NAME NAME, k.priority priority, " +
											" k.sl sl,v.description description,v.avatar_image avatar_image " +
											" FROM (SELECT   d.ID ID, d.description description, " +
													" d.avatar_image avatar_image,d.priority priority, d.created created " +
												" FROM vnt_media_content a,content_category_map b, " +
												" content_view c,CATEGORY d " +
												" WHERE a.ID = b.content_id(+) " +
												" AND b.category_id = d.ID(+) " +
												" AND a.ID = c.content_id(+) " +
												" AND b.category_id IN (SELECT ID " +
																		" FROM CATEGORY " +
																		" WHERE parent_id ="+parentId+")" +
										" GROUP BY d.ID,d.description,d.avatar_image,d.created,d.priority " +
										" ORDER BY d.priority ASC, d.created DESC) v, " +
										" (SELECT   d.ID, d.NAME NAME, d.priority priority, " +
													" SUM (c.download_count) sl " +
											" FROM vnt_media_content a,content_category_map b,content_view c,CATEGORY d " +
											" WHERE a.ID = b.content_id(+) " +
											" AND b.category_id = d.ID(+) " +
											" AND a.ID = c.content_id(+) " +
											" AND b.category_id IN (SELECT ID " +
																	" FROM CATEGORY " +
																	" WHERE parent_id ="+parentId+")" +
											" GROUP BY d.ID, d.NAME, d.priority, d.created " +
											" ORDER BY d.priority ASC, d.created DESC) k " +
											" WHERE v.ID = k.ID AND ROWNUM <= 20 " +
				               " ORDER BY DBMS_RANDOM.VALUE)) WHERE r <="+ endRec+"";
				
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			rs = preStmt.executeQuery();
			//System.out.println(strSql);
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("id", rs.getObject(1) == null ? "" : rs
						.getObject(1));
				attribute.put("name", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("priority", rs.getObject(3) == null ? "" : rs
						.getObject(3));				
				attribute.put("sl", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("description", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("avatar_image", rs.getObject(6) == null ? "" : rs
						.getObject(6));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListbyParent: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}	
	public ArrayList<DatabaseObject> getCategoryListHOTByParent(BigDecimal parentId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			int startRec = (page-1) * rowsPerPage + 1;
			int endRec = page * rowsPerPage;
				strSql = " SELECT * FROM ( " +
					" SELECT id, NAME, sl, description, avatar_image, ROWNUM AS r " +
					" FROM (SELECT k.id id, k.NAME NAME, k.sl sl, v.description description," +
					  			" v.avatar_image avatar_image" +
					  			" FROM (SELECT  d.id id, d.description description," +
					  						" d.avatar_image avatar_image" +
					  						" FROM vnt_media_content a," +
					  						"  content_category_map b," +
					  						"  content_view c," +
					  						"  CATEGORY d" +
					  					" WHERE a.id = b.content_id(+)" +
					  					" AND b.category_id = d.id(+)" +
					  					" AND a.id = c.content_id(+)" +
					  					" AND b.category_id IN (SELECT ID" +
					  											" FROM CATEGORY" +
					  											" WHERE parent_id ="+parentId+")" +
					  					" AND c.download_count IS NOT NULL" +
					  				" GROUP BY d.id, d.description, d.avatar_image) v," +
					  				" (SELECT   d.ID, d.NAME NAME, SUM (c.download_count) sl" +
					  					" FROM vnt_media_content a," +
					  						" content_category_map b," +
					  						"  content_view c," +
					  						"  CATEGORY d" +
					  					" WHERE a.id = b.content_id(+)" +
					  					" AND b.category_id = d.id(+)" +
					  					" AND a.id = c.content_id(+)" +
					  					" AND b.category_id IN (SELECT ID" +
					  											" FROM CATEGORY" +
					  											" WHERE parent_id ="+parentId+")" +
					  					" AND c.download_count IS NOT NULL" +
					  				" GROUP BY d.ID, d.NAME" +
					  				" ORDER BY sl DESC) k" +
					  	" WHERE v.ID = k.ID))" +
						" WHERE r between " + startRec+ " and "+endRec+" ";

			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			rs = preStmt.executeQuery();
			//System.out.println(strSql);
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("id", rs.getObject(1) == null ? "" : rs
						.getObject(1));
				attribute.put("name", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("sl", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("description", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("avatar_image", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListbyParent: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public ArrayList<DatabaseObject> getContentGameOffHOTListByType(BigDecimal typeId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			// int startRec = (page-1) * rowsPerPage + 1;
			// int endRec = page * rowsPerPage;
			strSql = "SELECT * FROM ("
				+ " SELECT ccat.priority, ccat.category_id, ctent.id, ctent.name, ctent.SUMMARIZE, "
				+ " ctent.PREVIEW_IMAGE, ctent.code, ctent.AVATAR_IMAGE, ctent.money money, a.data data " 
				+ " from vnt_media_content ctent, content_instance a, content_format b, CONTENT_CATEGORY_MAP ccat, content_view ctview"
				+ " WHERE ctent.id=ccat.content_id "
				+ " AND ctent.id = ctview.content_id "
				+ " AND ctent.id = a.content_id "
				+ " AND a.format_id = b.id "
				+ " AND b.code = 'JAR'"
				+ " AND ccat.category_id not in ('3627')"
				+ " AND ctent.status=1 and ctent.type_id=?"
				+ " AND ctent.preview_image IS NOT NULL"
				+ " AND ctent.avatar_image IS NOT NULL"
				+ " AND instr(ctent.preview_image,'PROMOTION_GIRL') <=0"
				+ " AND instr(ctent.preview_image,'_PG') <=0"
				+ " ORDER BY ctview.view_count DESC, ctview.download_count DESC)WHERE rownum <= 6";
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, typeId);

			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("category_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("id", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("name", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				attribute.put("summary", rs.getObject(5) == null ? "" : rs
						.getObject(5));
				attribute.put("preview_image", rs.getObject(6) == null ? ""
						: rs.getObject(6));
				attribute.put("code", rs.getObject(7) == null ? "" : rs
						.getObject(7));
				attribute.put("avatar_image", rs.getObject(8) == null ? "" : rs
						.getObject(8));
				attribute.put("money", rs.getObject(9) == null ? "" : rs
						.getObject(9)); 
				attribute.put("data", rs.getObject(10) == null ? "" : rs
						.getObject(10)); 				
				
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategory: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public ArrayList<DatabaseObject> getContentHOTListByTypeVn(BigDecimal typeId,
			int page, int rowsPerPage) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		ArrayList<DatabaseObject> result = null;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			strSql = "SELECT * FROM ("
					+ " SELECT ccat.content_group_id, ctent.content_id, ctent.name,ctent.code from content ctent"
					+ " left join cnt_cntg_map ccat on ctent.content_id=ccat.content_id WHERE ctent.content_type_id=?"
					+ " ORDER BY dbms_random.value)WHERE rownum <= 5";

			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			preStmt.setBigDecimal(1, typeId);

			rs = preStmt.executeQuery();
			result = new ArrayList<DatabaseObject>();
			while (rs.next()) {
				DatabaseObject object = new DatabaseObject();
				Hashtable<String, Object> attribute = new Hashtable<String, Object>();
				attribute.put("content_group_id", rs.getObject(1) == null ? "" : rs
						.getObject(1));
				attribute.put("content_id", rs.getObject(2) == null ? "" : rs
						.getObject(2));
				attribute.put("name", rs.getObject(3) == null ? "" : rs
						.getObject(3));
				attribute.put("code", rs.getObject(4) == null ? "" : rs
						.getObject(4));
				object.setAttribute(attribute);
				result.add(object);
			}

		} catch (Exception _e) {
			logger.error("getGameListByCategoryVn: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public int testLogin(String user, String pass) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		int result = 0;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			strSql = "select * from USER_INFO where user_name = '"+user+"' AND password = '"+pass+"'";
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			rs = preStmt.executeQuery();
			if (rs.next()) {
				result = rs.getInt(1);
			}
		} catch (Exception _e) {
			logger.error("test username and password: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}

	public int viewCount(BigDecimal viewId) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		int result = 0;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			strSql = "select view_count from vnt_media.content_view where content_id = "+viewId;
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			rs = preStmt.executeQuery();
			if (rs.next()) {
				result = rs.getInt(1);
			}

		} catch (Exception _e) {
			logger.error("view count: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	
	public int viewDownloadCount(BigDecimal viewId) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		int result = 0;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			strSql = "select download_count from vnt_media.content_view where content_id = "+viewId;
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			rs = preStmt.executeQuery();
			if (rs.next()) {
				result = rs.getInt(1);
			}

		} catch (Exception _e) {
			logger.error("view count: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public int viewDownloadCountFirst(BigDecimal catId) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		int result = 0;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			strSql = 
			" SELECT   SUM (c.download_count) sl " +
			" FROM vnt_media_content a, content_category_map b, content_view c,CATEGORY d " +
		    " WHERE d.ID=?" +
		    " AND a.ID = b.content_id(+)" +
			" AND b.category_id = d.ID(+)" +
			" AND a.ID = c.content_id(+)" +
			" AND b.category_id IN (SELECT ID" +
				" FROM CATEGORY" +
				" WHERE parent_id = 21763)" +
			" AND c.download_count IS NOT NULL" +
			" GROUP BY d.ID, d.NAME";
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			rs = preStmt.executeQuery();
			if (rs.next()) {
				result = rs.getInt(1);
			}

		} catch (Exception _e) {
			logger.error("view count: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public DatabaseObject getWeather(BigDecimal id) {
		ArrayList<DatabaseObject> games = findByDynamicWhere(
				Constant.DB_POOL_MWAP, "weather_forecasts", new String[] { "ID",
						"CODE", "ALIAS", "NAME", "CONTENT",
						"CREATED", "MODIFIED" },
				new String[] { null, null, null, null, null, null, null,
						}, "id=?",
				new Object[] { id }, null);

		if (games != null && !games.isEmpty())
			return games.get(0);
		return null;
	}

	public DatabaseObject getContent(BigDecimal id) {
		ArrayList<DatabaseObject> games = findByDynamicWhere(
				Constant.DB_POOL_MWAP, "vnt_media_content", new String[] { "id",
						"type_id", "url", "name", "summarize", "detail",
						"preview_image", "avatar_image", "avatar_image_w",
						"avatar_image_h", "status", "code", "money" },
				new String[] { null, null, null, null, null, null, null, null,
						null, null, null, null, null }, "id=?",
				new Object[] { id }, null);

		if (games != null && !games.isEmpty())
			return games.get(0);
		return null;
	}
	public DatabaseObject getContentVn(BigDecimal id) {
		ArrayList<DatabaseObject> games = findByDynamicWhere(
				Constant.DB_POOL_MWAP, "content", new String[] { "content_id",
						"content_type_id", "code", "name", "data", "created",
						"modified", "alias"},
				new String[] { null, null, null, null, null, null, null, null},"content_id=?",
				new Object[] { id }, null);

		if (games != null && !games.isEmpty())
			return games.get(0);
		return null;
	}
	public DatabaseObject getContentInstance(BigDecimal content_id) {
		ArrayList<DatabaseObject> games = findByDynamicWhere(
				Constant.DB_POOL_MWAP, "content_instance", new String[] { "id",
						"content_id", "format_id", "data_size", "data", "status",
						"created", "modified" },
				new String[] { null, null, null, null, null, null, null, null},
				"content_id=?",
				new Object[] { content_id }, null);

		if (games != null && !games.isEmpty())
			return games.get(0);
		return null;
	}
	public DatabaseObject getContentview(BigDecimal id) {
		ArrayList<DatabaseObject> games = findByDynamicWhere(
				Constant.DB_POOL_MWAP, "vnt_media.content_view",
				new String[] { "viewer_id", "content_id", "view_count",
						"last_view", "download_count", "last_download", "rank",
						"last_rank" }, new String[] { null, null, null, null,
						null, null, null, null }, "content_id=?",
				new Object[] { id }, null);

		if (games != null && !games.isEmpty())
			return games.get(0);
		return null;
	}
	public int checkCount(BigDecimal sId) {
		String strSql = null;
		Connection conn = null;
		PreparedStatement preStmt = null;
		ResultSet rs = null;
		int result = 0;
		try {
			conn = DBPool.getConnection(Constant.DB_POOL_MWAP);
			strSql = "select count(*) from vnt_media.content_view where content_id = "+sId;
			// prepare statement
			preStmt = conn.prepareStatement(strSql);
			rs = preStmt.executeQuery();
			if (rs.next()) {
				result = rs.getInt(1);
			}

		} catch (Exception _e) {
			logger.error("view count: Error executing " + strSql
					+ " >>> " + _e.toString());
		} finally {
			DBPool.releaseConnection(Constant.DB_POOL_MWAP, conn, preStmt, rs);
		}
		return result;
	}
	public boolean insertUserInfo(String user, String pass, String address, String mobile, String email) {
		DatabaseDAO databaseDAO = new DatabaseDAO();
		String sql = "insert into user_info(id, user_name, password, address, phone_number, email) values(user_seq.NEXTVAL,'"+user+"','"+pass+"','"+address+"','"+mobile+"','"+email+"')";
		return databaseDAO.executeSQLStatement(Constant.DB_POOL_MWAP, sql);
	}
	public boolean insertContentView(String id) {
		DatabaseDAO databaseDAO = new DatabaseDAO();
		String sql = "insert into content_view(viewer_id,content_id,view_count,last_view) values(seq_content_view.NEXTVAL,'"+id+"',1,sysdate)";
		return databaseDAO.executeSQLStatement(Constant.DB_POOL_MWAP, sql);
	}
	
	public boolean updateContentView(String id, int iCount) {
		DatabaseDAO databaseDAO = new DatabaseDAO();
		iCount++;
		String sql = "update content_view set view_count = "+iCount+" where content_id ="+id;
		return databaseDAO.executeSQLStatement(Constant.DB_POOL_MWAP, sql);
	}
	
	public boolean insertContentDown(String id) {
		DatabaseDAO databaseDAO = new DatabaseDAO();
		String sql = "insert into content_view(viewer_id,content_id,download_count,last_view) values(seq_Content_view.NEXTVAL,'"+id+"',1,sysdate)";
		return databaseDAO.executeSQLStatement(Constant.DB_POOL_MWAP, sql);
	}
	public boolean updateContentDownload(String id, int iCountDownload) {
		DatabaseDAO databaseDAO = new DatabaseDAO();
		iCountDownload++;
		String sql = "update content_view set download_count = "+iCountDownload+" where content_id ="+id;
		return databaseDAO.executeSQLStatement(Constant.DB_POOL_MWAP, sql);
	}
	//register and login

	public static void main(String[] args) {
		DBContentDAO contentDAO = new DBContentDAO();
		ArrayList<DatabaseObject> gameList = contentDAO.getGameListByCategory(new BigDecimal("203"), 1, 10);
		for (DatabaseObject game : gameList) {
			System.out.println(game.getAttribute().get("name") + "\n\t"
					+ game.getAttribute().get("summary"));
		}
	}
}
